<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class MemberOrderController extends Controller
{
    public function index()
    {
        return view('admin.memberOrder.index');
    }
    public function data(Request $request)
    {
        $model = \DB::table('member_order');
        if ($request->get('phone')){
            $model = $model->where('members.phone','like','%'.$request->get('phone').'%');
        }
        $res = $model
            ->select('member_order.*', 'members.phone as member_phone', 'store.name as store_name')
            ->leftJoin('members','members.id','=','member_order.member_id')
            ->leftJoin('store','store.id','=','member_order.store_id')
            ->orderBy('member_order.id','desc')
            ->paginate($request->get('limit',30))
            ->toArray();
        $data = [
            'code' => 0,
            'msg'   => 'ok...',
            'count' => $res['total'],
            'data'  => $res['data']
        ];
        return response()->json($data);
    }

    public function memberRechargeCardOrderIndex()
    {
        return view('admin.memberRechargeCardOrder.index');
    }

    public function memberRechargeCardOrderData(Request $request)
    {
        $model = \DB::table('member_recharge_card_order');
        if ($request->get('name')){
            $model = $model->where('member.phone','like','%'.$request->get('phone').'%');
        }
        $res = $model
            ->select('member_recharge_card_order.*', 'members.phone as member_phone')
            ->leftJoin('members','members.id','=','member_recharge_card_order.member_id')
            ->orderBy('member_recharge_card_order.id','desc')
            ->paginate($request->get('limit',30))
            ->toArray();
        $data = [
            'code' => 0,
            'msg'   => 'ok...',
            'count' => $res['total'],
            'data'  => $res['data']
        ];
        return response()->json($data);
    }

}
